package cn.xjfcloud.onedriveserver.init;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import cn.xjfcloud.onedriveserver.pojo.InitConfig;
import cn.xjfcloud.onedriveserver.pojo.dto.ApiConfig;
import cn.xjfcloud.onedriveserver.service.ApiConfigService;
import cn.xjfcloud.onedriveserver.service.CommonConfigService;

@Component
@ConfigurationProperties(prefix = "init")
public class InitApplicationRunner implements ApplicationRunner {

	@Autowired
	private ApiConfigService apiConfigService;
	
	@Autowired
	private InitConfig initConfig;
	
	@Autowired
	private CommonConfigService commonConfigService;
	
	@Override
	public void run(ApplicationArguments args) throws Exception {
		List<Integer> clientIds = initConfig.getClientId();
		for (Integer clientId : clientIds) {
			apiConfigService.getApiConfigById(clientId);
			commonConfigService.getCommonConfigById(clientId);
			Integer flag = apiConfigService.checkTokenStatus(clientId);
			if(flag == 1) {
				apiConfigService.getTokenByRefreshToken(clientId);
			}
		}
	}

}
